package org.lvslb.command;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by MelOnDev1 on 13/05/14.
 */
public class IPVSADMReceiver {

    String cmd = "";

    public void reset(){

    }
    public void removeAll(String ip , String port){

    }
    public void create(String ip , String port , String algorithmeType){

    }
    public void add(String ip , String port , String backEndIp, String weight,String method){

    }


    private String executeCommand(String command) {

        StringBuffer output = new StringBuffer();

        Process p = null;
        try {
            p = Runtime.getRuntime().exec(command);
            p.waitFor();
            BufferedReader reader =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line = "";
            while ((line = reader.readLine())!= null) {
                output.append(line + "\n");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(p!=null) p.destroy();
        }

        return output.toString();

    }

    public static void main(String[] args) {

        IPVSADMReceiver obj = new IPVSADMReceiver();

        String domainName = "google.com";

        //in mac oxs
        String command = "ping " + domainName;

        //in windows
        //String command = "ping -n 3 " + domainName;

        String output = obj.executeCommand(command);

        System.out.println(output);

    }


}
